package com.salmon.common.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;

import java.nio.charset.StandardCharsets;

/**
 * JWT 解析工具
 */
public class JwtHelper {

    public static Jws<Claims> parserToken(String jwtToken, byte[] key) {
        Jws<Claims> claimsJws = Jwts.parser().setSigningKey(key).parseClaimsJws(jwtToken);
        return claimsJws;
    }

    public static Claims parserToken(String jwtToken, String signature) {
        return parserToken(jwtToken,signature.getBytes(StandardCharsets.UTF_8)).getBody();
    }
}
